<?php

class Ajax
{
	public $load;
	
	function main()
	{
		$cmd = $_GET['cmd'];
		if($cmd != '' && $_SERVER['HTTP_X_REQUESTED_WITH'] != 'XMLHttpRequest')
		{
			die('Direct Access Denied');
		}
		switch($cmd)
		{
			case'notepad':
				$this->update_notepad();
			break;
			case'resetlogin':
				$this->set_read_login();
			break;
		}
		if($cmd != '') exit;
	}
	
	function update_notepad()
	{
		if(Input::post('note') !== NULL)
		{
			$note = $this->load->dashboard->notepad;
			if(strlen(trim($_POST['note'])) > 0)
			{
				$note = $_POST['note'];
				$this->base->db->execute('UPDATE ' . $this->base->db->prefix . 'dashboard_data SET `value` = \''. $this->base->db->escape($note) .'\' WHERE `key` = \'notepad\'');
				if($this->base->db->affected_rows() == 1 || $note == $this->load->dashboard->notepad)
				{
					echo 'The notepad has been updated.';
				}
				else
				{
					echo 'The notepad could not be saved.';
				}
			}
		}
	}
	
	function set_read_login()
	{
		$this->base->db->execute('UPDATE ' . $this->base->db->prefix . 'dashboard_login_logs SET `unread` = \'0\'');
		echo '0 Failed Attempts';
	}
}
?>